<!-- 
	作者：ZFJ
	时间：2017-05-06
	描述：这是个人信息页面
 -->
<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="./css/mui.min.css" rel="stylesheet" />
		
		<style type="text/css">
			.account:after{
				content: '';
			}
			.mui-table-view-cell>.mui-badge{
				right: 30px;
			}
		</style>
	</head>

	<body>
		
		<header class="mui-bar mui-bar-nav">
		    <h1 class="mui-title">个人信息</h1>
		</header>
		
		<div class="mui-content">
		    <ul class="mui-table-view">
	            <li class="mui-table-view-cell">
	                <a class="mui-navigate-right" id="pic">头像
	                	<span class="mui-badge mui-badge-inverted">
		                	<img id="img" src="./images/head.jpg"/ style="height:30px">
		                </span>
	                </a> 
	            </li>
	            <li class="mui-table-view-cell">
	                <a class="mui-navigate-right account">账号</a>
	                <span class="mui-badge mui-badge-inverted" id="account"></span>
	            </li>
	        </ul>
		</div>
		
		<canvas id="canvas"></canvas>
		
		<script src="./js/mui.min.js"></script>
		<script src="./js/jquery.js"></script>
		<script type="text/javascript">
			mui.init()
			
			var txt=window.sessionStorage.getItem('username');
			$('#account').html(txt);
			
			mui.plusReady(function() {
				mui('body').on('tap', '#pic', function() {
					var cmr = plus.camera.getCamera();
					var res = cmr.supportedImageResolutions[0];
					var fmt = cmr.supportedImageFormats[0];

					cmr.captureImage(function(e) {

						plus.io.resolveLocalFileSystemURL(e, function(cg) {
							var path = cg.toLocalURL(cg);
							$('#img').attr('src',path);
							var image=$('#canvas').toDataURL(path);
							$.ajax({
								url:'http://10.20.159.23:3000/register',
								dataType:'json',
								data:'username='+txt+'&userimg='+image,
								success:function(res){					
									if (res && res.code == 0) {
										alert(res.message);
									}
				    			},
				    			error:function(){
				    				alert('保存失败！')
				    			}
							})
						}, function(err) {
							
						})
					},
						function(error) {
							console.log('用户取消拍照')
					
						}, {
							resolution: res,
							format: fmt,
							index: '1'// 1 是主摄像头 2是副摄像头
						}
					);
				})
			})

			
		</script>
	</body>

</html>